Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
function returning [object Promise]

I'm trying to return the value of the first function, and use as variable on the second function, but it's showing this [object Promise].

addEventListener("fetch", event => {
  event.respondWith(fetchAndStream(event.request))
});

async function handleRequest(request) {
      var uri = request.url.replace(/^https:\/\/.*?\//gi, "/");
      return uri;
}

async function fetchAndStream() {

    uri = handleRequest();
    console.log(uri);
    // Fetch from origin server.
    let response = await fetch('http://blablabla.com/' + uri);

    const responseInit = {
        headers: {
            'Content-Type': 'application/octet-stream',
            'Content-Disposition': 'attachment; filename="file.m3u"',
        }
    };

    // ... and deliver our Response while that's running.
    return new Response(response.body, responseInit)
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are calling your functions incorrectly without arguments. Your handleRequest takes an argument request in your function declaration

async function handleRequest(request) 

In your event listener you are calling the callback with an argument

fetchAndStream(event.request)

But you don't take any arguments here.

async function fetchAndStream() {

    uri = handleRequest();
    console.log(uri);

Since you have used your function handleRequest with async. It returns a promise wrapper which will await the execution, which I have doubts it will complete from there. The wrapper is like a placeholder which will be filled once your promise completes but since you are not calling the functions properly. Hence you are getting the output.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!